package com.somsoft.handjc.util;

import java.util.ArrayList;
import java.util.List;

import org.apache.http.NameValuePair;
import org.json.JSONArray;
import org.json.JSONObject;

import com.somsoft.handjc.xuncha.po.ZhongHe;

/**
 * 效能巡查 数据获取
 * 
 * 
 */
public class XunChaDataUtil {

	public static JSONArray rankData = new JSONArray();
	public static List<String> xunchaDeptNames = null;
	public static List<String> xunchaLeaderNames = null;
	
	//部门名称
	public static JSONArray getDeptNames() throws Exception {
		try {
			String s = Utils.getJsonData(Utils.SERVER_IP+"/handweb/xuncha/xuncha!getDeptNames.hand",new ArrayList<NameValuePair>());
			JSONArray jArray = new JSONArray(s);
			return jArray;
		} catch (Exception e) {
			throw e;
		}
	}
	
	//责任区领导
	public static JSONArray getLeaderNames() throws Exception {
		try {
			String s = Utils.getJsonData(Utils.SERVER_IP+"/handweb/xuncha/xuncha!getLeaderNames.hand",new ArrayList<NameValuePair>());
			JSONArray jArray = new JSONArray(s);
			return jArray;
		} catch (Exception e) {
			throw e;
		}
	}
			
	//业务量（柱状图、折线图）
	public static JSONArray getBusinessCount(List<NameValuePair> params) throws Exception {
		try {
			String s = Utils.getJsonData(Utils.SERVER_IP+"/handweb/xuncha/xuncha!businessCount.hand",params);
			JSONArray jArray = new JSONArray(s);
			return jArray;
		} catch (Exception e) {
			throw e;
		}
	}
	//投资完成情况
	public static JSONArray getTouzhiFinish(List<NameValuePair> params) throws Exception {
		try {
			String s = Utils.getJsonData(Utils.SERVER_IP+"/handweb/xuncha/xuncha!touzhiFinish.hand",params);
			JSONArray jArray = new JSONArray(s);
			return jArray;
		} catch (Exception e) {
			throw e;
		}
	}
	//投资类型
	public static JSONArray getTouzhiType(List<NameValuePair> params) throws Exception {
		try {
			String s = Utils.getJsonData(Utils.SERVER_IP+"/handweb/xuncha/xuncha!touzhiType.hand",params);
			JSONArray jArray = new JSONArray(s);
			return jArray;
		} catch (Exception e) {
			throw e;
		}
	}
	//巡查业务对比图
	public static JSONArray getPatrolDuibi(List<NameValuePair> params) throws Exception {
		try {
			String s = Utils.getJsonData(Utils.SERVER_IP+"/handweb/xuncha/xuncha!patrolDuibi.hand",params);
			JSONArray jArray = new JSONArray(s);
			return jArray;
		} catch (Exception e) {
			throw e;
		}
	}
	//各单位业务对比图
	public static JSONArray getDeptBusinessDuibi(List<NameValuePair> params) throws Exception {
		try {
			String s = Utils.getJsonData(Utils.SERVER_IP+"/handweb/xuncha/xuncha!deptBusinessDuibi.hand",params);
			JSONArray jArray = new JSONArray(s);
			return jArray;
		} catch (Exception e) {
			throw e;
		}
	}
	//绩效排名
	public static JSONArray getJiXiaoRank(List<NameValuePair> params) throws Exception {
		try {
			String s = Utils.getJsonData(Utils.SERVER_IP+"/handweb/xuncha/xuncha!jiXiaoRank.hand",params);
			JSONArray jArray = new JSONArray(s);
			return jArray;
		} catch (Exception e) {
			throw e;
		}
	}
	
	//绩效排名明细
	public static JSONObject getJiXiaoRankDetail(List<NameValuePair> params) throws Exception {
		try {
			String s = Utils.getJsonData(Utils.SERVER_IP+"/handweb/xuncha/xuncha!jiXiaoRankDetail.hand",params);
			JSONObject jArray = new JSONObject(s);
			return jArray;
		} catch (Exception e) {
			throw e;
		}
	}
	
	public static JSONObject getJiXiaoRankDetail(String deptName) throws Exception {
		JSONObject obj = null;
		try {
			for(int i=0;i<rankData.length();i++){
				obj = rankData.getJSONObject(i);
				if(deptName.equals(obj.getString("deptName"))){
					break;
				}
			}
		} catch (Exception e) {
			throw e;
		}
		return obj;
	}
	
	/**
	 * 综合查询
	 * 
	 * @return
	 * @throws Exception
	 */
	public static JSONArray getBusinessInfo(List<NameValuePair> params) throws Exception {
//		List<BusinessInfo> list = new ArrayList<BusinessInfo>();
		try {
			String s = Utils.getJsonData(Utils.SERVER_IP+"/handweb/xuncha/xuncha!findBusiness.hand",params);
			JSONArray jArray = new JSONArray(s);
			return jArray;
//			for (int i = 0; i < jArray.length(); i++) {
//				JSONObject obj = jArray.getJSONObject(i);
//				BusinessInfo bi = new BusinessInfo();
//				bi.setBusinessId(obj.getString("id"));
//				bi.setProjectName(obj.getString("projectName"));
//				bi.setProjectCode(obj.getString("projectCode"));
//				bi.setDeptName(obj.getString("deptName"));
//				bi.setDeptPhone(obj.getString("deptPhone"));
//				bi.setLeaderName(obj.getString("leaderName"));
//				bi.setLeaderJob(obj.getString("leaderJob"));
//				bi.setLeaderPhone(obj.getString("leaderPhone"));
//				bi.setTouzhiType(obj.getString("touzhiType"));
//				
//				bi.setTotalPage(Integer.parseInt(obj.getString("totalPage")));
//				list.add(bi);
//			}
		} catch (Exception e) {
			throw e;
		}
	}
	
	//获取反馈信息
	public static JSONArray getFeedback(List<NameValuePair> params) throws Exception {
		try {
			String s = Utils.getJsonData(Utils.SERVER_IP+"/handweb/xuncha/xuncha!findBusinessFeedback.hand",params);
			JSONArray jArray = new JSONArray(s);
			return jArray;
		} catch (Exception e) {
			throw e;
		}
	}
	
	/**
	 * 综合监察
	 * @param params
	 * @return
	 * @throws Exception
	 */
	public static List<ZhongHe> getZhongHeJc(List<NameValuePair> params) throws Exception {
		List<ZhongHe> list = new ArrayList<ZhongHe>();
		try {
			String s = Utils.getJsonData(Utils.SERVER_IP+"/handweb/xuncha/xuncha!zhongheJc.hand",params);
			JSONArray jArray = new JSONArray(s);
			for (int i = 0; i < jArray.length(); i++) {
				JSONObject obj = jArray.getJSONObject(i);
				ZhongHe zh = new ZhongHe();
				zh.setJcName(obj.getString("jcName"));
				zh.setZcCount(obj.getString("zcCount"));
				zh.setAlertCount(obj.getString("alertCount"));
				zh.setYellowCount(obj.getString("yellowCount"));
				zh.setRedCount(obj.getString("redCount"));
				
				zh.setZcPercent(obj.getString("zcPercent"));
				zh.setAlertPercent(obj.getString("alertPercent"));
				zh.setYellowPercent(obj.getString("yellowPercent"));
				zh.setRedPercent(obj.getString("redPercent"));
				list.add(zh);
			}
		} catch (Exception e) {
			throw e;
		}
		return list;
	}
}
